package com.cr.admin.business.city.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cr.admin.business.city.dao.mapper.CityMapper;
import com.cr.admin.business.city.dao.repository.CityRepository;
import com.cr.admin.business.city.pojo.entity.City;
import com.cr.admin.business.city.pojo.param.CityAddParam;
import com.cr.admin.business.city.pojo.param.CityUpdateParam;
import com.cr.admin.business.city.pojo.query.CityQuery;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository

public class CityRepositoryImpl implements CityRepository {

    @Autowired
    private CityMapper cityMapper;


    @Override
    public List<City> selectCity(CityQuery cityQuery) {
        QueryWrapper<City> queryWrapper= new QueryWrapper<>();

        if(cityQuery.getName()!=null){
            queryWrapper.like("name",cityQuery.getName());
        }
        if(cityQuery.getPinyin()!=null){
            queryWrapper.like("pinyin",cityQuery.getPinyin());
        }

        return cityMapper.selectList(queryWrapper);

    }

    @Override
    public void addCity(CityAddParam cityAddParam) {
        City city=new City();
        BeanUtils.copyProperties(cityAddParam,city);
        cityMapper.insert(city);
    }

    @Override
    public void updateById(CityUpdateParam topicUpdateParam) {
        City city=new City();
        BeanUtils.copyProperties(topicUpdateParam,city);
        cityMapper.updateById(city);
    }

    @Override
    public City selectById(Long id) {
        return cityMapper.selectById(id);
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        cityMapper.deleteBatchIds(ids);
    }
}
